package com.bringway.p2p.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bringway.framework.util.DateUtils;
import com.bringway.p2p.dao.TjbbDao;
import com.bringway.p2p.service.TjbbService;
import net.sf.json.JSONObject;
@Service
@Transactional
public class TjbbServiceImpl implements TjbbService {
	@Autowired
	private TjbbDao tjbbDao;

	@Override
	public List<Map<String, Object>> queryTjbbDayList(String tjDate) {
		return tjbbDao.queryTjbbDayList(tjDate);
	}
	@Override
	public List<Map<String, Object>> queryTjbbDayReport(JSONObject params) {
		return tjbbDao.queryTjbbDayReport(params);
	}

	@Override
	public Map<String, Object> getSumTjbbDay(String tjDate) {
		return tjbbDao.getSumTjbbDay(tjDate);
	}

	@Override
	public List<Map<String, Object>> queryTjbbMonthList(String tjym) {
		return tjbbDao.queryTjbbMonthList(tjym);
	}

	@Override
	public Map<String, Object> getSumTjbbMonth(String tjym) {
		return tjbbDao.getSumTjbbMonth(tjym);
	}

	@Override
	public List<Map<String, Object>> queryTjbbDayListByOa(JSONObject params) {
		return tjbbDao.queryTjbbDayListByOa(params);
	}

	@Override
	public int getTjbbDayListByOaCount(JSONObject params) {
		return tjbbDao.getTjbbDayListByOaCount(params);
	}

	@Override
	public List<Map<String, Object>> queryTjbbMonthListByOa(JSONObject params) {
		return tjbbDao.queryTjbbMonthListByOa(params);
	}

	@Override
	public int getTjbbMonthListByOaCount(JSONObject params) {
		return tjbbDao.getTjbbMonthListByOaCount(params);
	}

	@Override
	public Map<String, Object> queryTjbbZzMap() {
		return tjbbDao.queryTjbbZzMap();
	}

	@Override
	public List<Map<String, Object>> querySyAndBjList(String type, String tjDate,Integer start,Integer limit) {
		return tjbbDao.querySyAndBjList(type, tjDate,start,limit);
	}

	@Override
	public int getSyAndBjCount(String type, String tjDate) {
		return tjbbDao.getSyAndBjCount(type, tjDate);
	}

	@Override
	public String getSyAndBjSum(String type, String tjDate) {
		return tjbbDao.getSyAndBjSum(type, tjDate);
	}

	@Override
	public Map<String, Object> queryTjbbZzMapSearch(String startDate, String endDate) {
		return tjbbDao.queryTjbbZzMapSearch(startDate, endDate);
	}

	@Override
	public Map<String, String> getZzMap(String startDate, String endDate) {
		if (StringUtils.isEmpty(startDate)) {
			startDate="2016-01-01";
		}
		if (StringUtils.isEmpty(endDate)) {
			endDate=DateUtils.getCurrentDataStr();
		}
		//更新日期时序表
		this.tjbbDao.saveSysDateSort(startDate, endDate);
		//删除当天统计数据数据
		//获取未生成缓存数据的日期
		List<String> list=tjbbDao.listNotCacheZzDate(startDate, endDate);
		//插入未缓存数据
		for (String gsDate : list) {
			tjbbDao.insertCacheTableZZ(gsDate);
		}
		//查询数据
		return tjbbDao.getZzMap(startDate, endDate);
	}

	@Override
	public List<Map<String, Object>> listSysSy(JSONObject params) {
		return tjbbDao.listSysSy(params);
	}

	@Override
	public int getSysSyCount(JSONObject params) {
		return tjbbDao.getSysSyCount(params);
	}

	@Override
	public String getSysSySumJe(JSONObject params) {
		return tjbbDao.getSysSySumJe(params);
	}

}
